package ar.edu.itba.it.paw.domain;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

@Entity
public class Offer extends PersistentAttributes{

	private Float offer;
	@ManyToOne
	private User user;
	private Date offer_date;
	@ManyToOne
	private Auction auction;

	protected Offer(){

	}
	
	public Offer(float offer, User user, Date offer_date, Auction auction){
		System.out.println("El auction es null?? " + auction);
		setAuction(auction);
		setOffer(offer);
		setUser(user);
		setOffer_date(offer_date);
	}

	private void setOffer(Float offer) {
		if(offer == null)
			throw new IllegalArgumentException();
		this.offer = offer;
	}

	public Float getOffer() {
		return offer;
	}

	private void setUser(User user) {
		if(user == null){
			throw new IllegalArgumentException("Null User");
		}
		this.user = user;
	}

	public User getUser() {
		return user;
	}

	private void setOffer_date(Date offer_date) {
		this.offer_date = offer_date;
	}

	public Date getOffer_date() {
		return offer_date;
	}
	
	private void setAuction(Auction auction){
		this.auction = auction;
	}
	
	public Auction getAuction(){
		return this.auction;
	}
	
	public String toString(){
		return "offer: " + offer;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((offer == null) ? 0 : offer.hashCode());
		result = prime * result
				+ ((offer_date == null) ? 0 : offer_date.hashCode());
		result = prime * result + ((user == null) ? 0 : user.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Offer other = (Offer) obj;
		if (offer == null) {
			if (other.offer != null)
				return false;
		} else if (!offer.equals(other.offer))
			return false;
		if (offer_date == null) {
			if (other.offer_date != null)
				return false;
		} else if (!offer_date.equals(other.offer_date))
			return false;
		if (user == null) {
			if (other.user != null)
				return false;
		} else if (!user.equals(other.user))
			return false;
		return true;
	}
}
